package cn.dapeng.rocket.config;

import cn.dapeng.rocket.message.RocketMessageOperate;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.util.Assert;

/**
 * @BelongProject message-queue
 * @BelongPackage cn.dapeng.rocket.config
 * @Description TODO
 * @ClassName RocketAutoConfiguration
 * @Author xupenghong
 * @Date 2024/6/28 10:04
 * @Version 1.0.0
 */
@Configuration
@EnableConfigurationProperties({RocketProperties.class})
public class RocketAutoConfiguration {

    @Bean
    public RocketTemplate rocketTemplate(RocketProperties rocketProperties) {
        Assert.hasText(rocketProperties.getNameServer(), "nameServer must not be null");
        Assert.hasText(rocketProperties.getTopic(), "topic must not be null");

        RocketTemplate rocketTemplate = new RocketTemplate();
        rocketTemplate.setNameServer(rocketProperties.getNameServer());

        return rocketTemplate;
    }

    @Bean
    @DependsOn({"rocketTemplate"})
    public RocketMessageOperate rocketMessageOperate(RocketTemplate rocketTemplate) {
        return new RocketMessageOperate(rocketTemplate);
    }

}
